package com.five.calendar;

import android.content.Context;
import android.content.res.Configuration;

import com.five.calendar.utils.SpUtils;

import java.util.Locale;

/**
 * Created by zhuxiaoxin on 2017/8/26.
 */
public class CalendarApp extends BaseApp {

    private Locale mLastLocale;

    @Override
    public void onCreate() {
        super.onCreate();
        SpUtils.setContext(this);
        mLastLocale = getResources().getConfiguration().locale;
    }

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        if ((null != mLastLocale) && !newConfig.locale.equals(mLastLocale)) {
            mLastLocale = newConfig.locale;
            exit();
        }
    }

    public static void exit() {
        ApplicationHelper.postRunInUiThread(new Runnable() {
            @Override
            public void run() {
                android.os.Process.killProcess(android.os.Process.myPid());
            }
        });
    }
}
